Imports System.Xml.Serialization
Namespace SSDL

    Public Class EntityType
        Inherits XEntityModelElementWithDocumentationBase

        ''' <summary>Initializes an instance of the <see cref="EntityType" /> class.
        ''' This is the default constructor for this class.</summary>
        Public Sub New()
            MyBase.New("EntityType", SsdlXmlNamespace)
        End Sub

        ''' <summary>Initializes an instance of the <see cref="EntityType" /> class.</summary>
        ''' <param name="other">An <see cref="System.Xml.Linq.XElement"/> object to copy from.</param>
        Public Sub New(ByVal other As XElement)
            MyBase.New(other)
        End Sub

        Private __Properties As EntityPropertyBaseCollection
        Private __NavigationProperties As NavigationPropertyBaseCollection

        <AutoLoad()> _
        <XmlElement("Key")> _
        Public Property Key() As EntityKeyElement
            Get
                Return DirectCast(Me.Element(MyBase.Name.Namespace + "Key"), EdmxEditor.EntityKeyElement)
            End Get
            Set(ByVal value As EntityKeyElement)
                If (DirectCast(value, XElement).Name <> (MyBase.Name.Namespace + "Key")) Then
                    Throw New ArgumentException("Invalid Element")
                End If
                If (Me.Key IsNot Nothing) Then
                    Me.Key.Remove()
                End If
                Me.Add(New EdmxEditor.EntityKeyElement(value))
            End Set
        End Property

        <AutoLoad()> _
        <XmlElement("NavigationProperty", GetType(NavigationProperty))> _
        Public ReadOnly Property NavigationProperties() As NavigationPropertyBaseCollection
            Get
                If (__NavigationProperties Is Nothing) Then
                    __NavigationProperties = New EdmxEditor.NavigationPropertyBaseCollection(Me, MyBase.Name.Namespace, "NavigationProperty")
                End If
                Return __NavigationProperties
            End Get
        End Property

        <XmlAttribute()> _
        Public Shadows Property Name() As String
            Get
                Return Me.@Name
            End Get
            Set(ByVal value As String)
                Me.@Name = value
            End Set
        End Property

        <AutoLoad()> _
        <XmlElement("Property", GetType(EntityProperty))> _
        Public ReadOnly Property Properties() As EntityPropertyBaseCollection
            Get
                If (__Properties Is Nothing) Then
                    __Properties = New EdmxEditor.EntityPropertyBaseCollection(Me, MyBase.Name.Namespace, "Property")
                End If
                Return __Properties
            End Get
        End Property

    End Class

End Namespace
